import 'package:flutter/material.dart';
import 'package:flutter_buisiness_2006a/provider/cart_provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

class CartBottom extends StatefulWidget {
  const CartBottom({Key? key}) : super(key: key);

  @override
  State<CartBottom> createState() => _CartBottomState();
}

class _CartBottomState extends State<CartBottom> {
  //全选按钮
  Widget _selectAllBtn(context) {
    return Row(
      children: [
        Checkbox(
          value: Provider.of<CartProvider>(context).isAllCheck,
          onChanged: (val) {
            Provider.of<CartProvider>(context,listen: false).changeAllCheckBtnState(val!);
          },
          activeColor: Colors.pink,
        ),
        const Text('全选')
      ],
    );
  }

  //合计区域
  Widget _allPriceArea(context) {
    return Container(
      width: ScreenUtil().setWidth(430).toDouble(),
      alignment: Alignment.centerRight,
      child: Column(
        children: [
          Row(
            children: [
              Container(
                alignment: Alignment.centerRight,
                width: ScreenUtil().setWidth(280).toDouble(),
                child: Text(
                  '合计:',
                  style: TextStyle(fontSize: ScreenUtil().setSp(36).toDouble()),
                ),
              ),
              Container(
                alignment: Alignment.centerLeft,
                width: ScreenUtil().setWidth(150).toDouble(),
                child: Text(
                  '￥${Provider.of<CartProvider>(context).allPrice}',
                  style: TextStyle(
                      fontSize: ScreenUtil().setSp(30).toDouble(),
                      color: Colors.red),
                ),
              )
            ],
          ),
          Container(
            width: ScreenUtil().setWidth(430).toDouble(),
            alignment: Alignment.centerRight,
            child: Text(
              '满10元免配送费,预约免配送费',
              style: TextStyle(
                  color: Colors.black38,
                  fontSize: ScreenUtil().setSp(22).toDouble()),
            ),
          )
        ],
      ),
    );
  }

  //结算按钮
  Widget _goButton(context) {
    return Container(
      width: ScreenUtil().setWidth(160).toDouble(),
      padding: const EdgeInsets.only(left: 10),
      child: InkWell(
        onTap: () {},
        child: Container(
          padding: const EdgeInsets.all(10),
          alignment: Alignment.center,
          decoration: BoxDecoration(
              color: Colors.red, borderRadius: BorderRadius.circular(3)),
          child: Text(
            '结算(${Provider.of<CartProvider>(context).allGoodsCount})',
            style: const TextStyle(color: Colors.white),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.all(5),
      color: Colors.white,
      width: ScreenUtil().setWidth(750).toDouble(),
      child: Row(
        children: [_selectAllBtn(context), _allPriceArea(context), _goButton(context)],
      ),
    );
  }
}
